package ezXpns;

import java.lang.reflect.Type;
import java.util.Date;

import com.google.gson.*;


//@author A0088827L
public class SerializationConfig {
	public static Gson getGson() {
		return BUILDER.create();
	}
	
	private static class DateSerializer implements JsonSerializer<Date>, JsonDeserializer<Date> {
		public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
			return new JsonPrimitive(src.getTime());
		}
		
		public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
			      throws JsonParseException {
			return new Date(json.getAsLong());
		}
	}
	
	static {
		GsonBuilder builder = new GsonBuilder();
		builder.registerTypeAdapter(Date.class, new DateSerializer());		
		
		BUILDER = builder;
	}
	
	private static final GsonBuilder BUILDER;
}
